package cn.tedu.imop.content.controller;

import cn.tedu.imop.api.model.RestResult;
import cn.tedu.imop.api.model.RestResultUtils;
import cn.tedu.imop.common.constants.Constants;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.content.entity.ArticleCategory;
import cn.tedu.imop.content.service.ArticleCategoryService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "文章分类管理")
@RestController
@RequestMapping(Constants.CONTROLLER_API_VERSION+"/article/category")
public class ArticleCategoryController {
    private final ArticleCategoryService articleCategoryService;

    public ArticleCategoryController(ArticleCategoryService articleCategoryService) {
        this.articleCategoryService = articleCategoryService;
    }
    @ApiOperation("添加分类")
    @PostMapping
    public RestResult createArticleCategory(ArticleCategory articleCategory) {
         articleCategoryService.createArticleCategory(articleCategory);
         return RestResultUtils.success();
    }
    @ApiOperation("分类列表")
    @GetMapping
    public RestResult<PageData<ArticleCategory>> getArticleCategoryList(ArticleCategory articleCategory) {
        return RestResultUtils.success(articleCategoryService.getArticleCategoryList(articleCategory));
    }
    @ApiOperation("二级分类")
    @GetMapping("/list/second")
    public RestResult<List<ArticleCategory>> getArticleCategoryList() {
        return RestResultUtils.success(articleCategoryService.getArticleCategoryList());
    }
}
